package com.vive;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IFormSubmitter;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.util.lang.Bytes;

import java.io.File;
import java.io.IOException;

public class FileUploadPage extends WebPage {

    private FileUploadField imageUpload;
    private Form<Void> form;

    public FileUploadPage() {
    	super();
        imageUpload = new FileUploadField("imageUpload");
        form = new Form<Void>("formUp"){
            private static final long serialVersionUID = 1L;

            protected void onSubmit() {
                final FileUpload upload = imageUpload.getFileUpload();
                if (upload != null) {
                    try {
                        upload.writeTo(new File("d:\\1.txt"));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                super.onSubmit();
            }
        };
        form.add(imageUpload);
        form.setMaxSize(Bytes.kilobytes(1000));
        form.setMultiPart(true);
        add(form);

    }
}
